# ./constants.py -- Define all constants
#coding:utf-8

# Import Needs
import os
import json
import copy

# Logging
DEBUG, INFO, WARNING, ERROR, FATAL = range(5)
LEVEL = ("debug", "info", "warning", "error", "fatal")

# Path

while True:
    try:
        _f = open("selfcheck.py") # Test if at root path.
    except FileNotFoundError:
        os.chdir("..")    # Step back a directory.
    else:
        _f.close()
        break
ROOT_PATH = os.getcwd()
NLPF_JSON_PATH = os.path.join(ROOT_PATH, "assets/memory/nlpf.json")
LOG_FILE_PATH = os.path.join(ROOT_PATH, "assets/logs/")


# Read NLP Files
with open(NLPF_JSON_PATH) as _f:
    _data = _f.read()
NLPF = json.loads(_data)
PUNCTUATIONS = NLPF["punctuations"]
CORPORA = NLPF["corpora"]


# Save to NLP Files
# Function: save_nlpf()
def save_nlpf(key, json_r):
    """The function for saving NLP Files

    Args:
        key (str): The key you wish to modify
        json_r (any, usually list and dict): The modify you wish to do

    Returns:
        str: Nothing to say.
    """    
    _nlpf_copy = copy.deepcopy(NLPF)
    _nlpf_copy[key] = json_r
    _nlpf_copy = json.dumps(_nlpf_copy)
    with open(NLPF_JSON_PATH, 'w') as _f:
        _f.write(_nlpf_copy)
    return "Done"
